package com.kuaimacode.kframework.api.service.config;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kuaimacode.kframework.mybatis.mapper.agent.SysAgentWeatherMapper;
import com.kuaimacode.kframework.mybatis.models.agent.SysAgentWeather;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * <p>
 * 分站特殊天气 服务实现类
 * </p>
 *
 * @author Bean
 * @since 2019-03-12
 */
@Service
public class SysAgentWeatherService extends ServiceImpl<SysAgentWeatherMapper, SysAgentWeather> implements IService<SysAgentWeather> {


    /**
     *  分页查找所有的用户
     * @param pageNum 当前页码，从1开始
     * @param pageSize  一页显示多少行
     * @return
     */
    public PageInfo<SysAgentWeather> findAll(int pageNum, int pageSize) {
        PageHelper.startPage(pageNum, pageSize,true,false,null);
        List<SysAgentWeather> weathers = baseMapper.selectList(null);
        return new PageInfo<SysAgentWeather>(weathers);
    }

    /**
     * 获取分站配置的特殊天气（已生效的）
     * @param agentId
     * @return
     */
    public List<SysAgentWeather> getRealTimeAgentWeather(String agentId){
        QueryWrapper<SysAgentWeather> qryWrapper = new QueryWrapper<>();
        qryWrapper.eq("agent_id", agentId);
        Date now = new Date();
        qryWrapper.ge("end_time",now);
        qryWrapper.le("start_time",now);
        return baseMapper.selectList(qryWrapper);
    }

}
